package lambda;

import java.util.ArrayList;
import java.util.function.Function;
import java.util.function.IntBinaryOperator;
import java.util.function.IntPredicate;

public class LambdaTest {

    public static void main(String[] args) {
        new Thread(()->{
            System.out.println(Thread.currentThread().getName() + "执行lamdba表达式");
        }).start();


        int res = cacl(new IntBinaryOperator() {
            @Override
            public int applyAsInt(int left, int right) {
                return left + right;
            }
        });
        System.out.println(res);


        int res2 = cacl((int left,int right)-> {
                return left + right;
        });
        System.out.println(res2);


        printNum((int value) ->{
            return value%2 == 0;
        });

        Integer res3 = typeConver(new Function<String, Integer>() {
            @Override
            public Integer apply(String s) {
                return Integer.valueOf(s);
            }
        });
        System.out.println(res3);

        Integer res4 = typeConver((String s) ->{
            return Integer.valueOf(s);
        });
        System.out.println(res4  );

    }

    public static int cacl(IntBinaryOperator intBinaryOperator){
        int a = 10;
        int b = 20;
        return intBinaryOperator.applyAsInt(a,b);
    };

    public static void printNum(IntPredicate intPredicate){

        int[] arr = {1,2,3,4,5,6,7};
        for (int i : arr) {
            if(intPredicate.test(i)){
                System.out.println(i);
            }

        }
        
    };

    public static <R> R typeConver(Function<String,R> function){
        String str = "1234";
        R result = function.apply(str);
        return result;
    }
}
